package common;

public class fib {

    public static long fibLogic(int n) {
        if (n < 2) {
            return n;
        }

        return fibLogic(n - 1) + fibLogic(n - 2);
    }

    public static long fibArray(int n) {
        if (n < 2) {
            return n;
        }

        int[] data = new int[n];
        data[0] = 0;
        data[1] = 1;
        for (int i = 2; i < n; i++) {
            data[i] = data[i - 1] + data[i - 2];
        }

        return data[n - 1];
    }

    public static long fibOnly(int n) {
        if (n < 2) {
            return n;
        }
        int a, i = 0;
        int b = 1, c = 1;
        while (i < n) {
            // 0 1 1
            // 0 1 1 2
            a = b;
            b = c;
            c = a + b;
            i++;
        }

        return c;
    }

    public static void main(String[] args) {
        long now = System.currentTimeMillis();
//        System.out.println(fibLogic(47));
//        System.out.println(fibArray(77));
//        System.out.println(fibOnly(74));
        System.out.println(System.currentTimeMillis() - now);
    }
}
